package com.pan.test.controller;

import com.pan.test.entity.vo.PaymentVO;
import com.pan.test.entity.vo.ResponseVO;
import com.pan.test.service.PaymentService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/payment")
public class PaymentController {

    @Resource
    private PaymentService paymentService;

    /**
     * 创建套餐购买订单
     */
    @PostMapping(value = "/create", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<Map<String, Object>> createPackageOrder(@RequestBody PaymentVO paymentVO) {
        Map<String, Object> result = paymentService.createPackageOrder(paymentVO);
        return ResponseVO.success(result);
    }

    /**
     * 处理支付回调
     */
    @PostMapping("/callback/{orderId}")
    public ResponseVO<Void> handlePaymentCallback(
            @PathVariable String orderId,
            @RequestParam String transactionId) {
        paymentService.handlePaymentCallback(orderId, transactionId);
        return ResponseVO.success();
    }

    /**
     * 获取支付记录
     */
    @GetMapping("/records")
    public ResponseVO<Map<String, Object>> getPaymentRecords(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        Map<String, Object> result = paymentService.getPaymentRecords(pageNum, pageSize);
        return ResponseVO.success(result);
    }

    /**
     * 获取当前套餐信息
     */
    @GetMapping("/current-package")
    public ResponseVO<Map<String, Object>> getCurrentPackage() {
        Map<String, Object> result = paymentService.getCurrentPackage();
        return ResponseVO.success(result);
    }
} 